import datetime
import os
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


class driver:
    driver = ""
    options = ""
    def __init__(self):
        self.options = webdriver.ChromeOptions()
        self.options.page_load_strategy = 'eager'
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=self.options)
        self.driver.implicitly_wait(5)


    def getwinshot(self):  #截图
        time = datetime.datetime.now().strftime("%Y-%m-%d")
        if not os.path.exists("../img/" + time): #如果路径不存在
            os.mkdir("../img/" + time) #创建路径
        filename = datetime.datetime.now().strftime("%H_%M_%S") + "-" + sys._getframe().f_back.f_code.co_name  + '.png'
        self.driver.save_screenshot("../img/" + time  + '/' + filename)
forum_driver = driver()
